package com.jzcn.common.file;

public class FileNameProcessor {

    private FileNameProcessor() {

    }

    public static FileName process(String fileFullName) {
        if (fileFullName != null) {
            Integer lastPointPosition = fileFullName.lastIndexOf(".");
            if (lastPointPosition != -1) {
                String fileName = fileFullName.substring(0, lastPointPosition);
                String suffix = fileFullName.substring(lastPointPosition + 1, fileFullName.length());
                return new FileName(fileName, suffix);
            } else {
                return new FileName(fileFullName, null);
            }
        } else {
            return new FileName(null, null);
        }
    }

    public static class FileName {
        private String name;
        private String type;

        public FileName(String name, String type) {
            this.name = name;
            this.type = type;
        }

        public String generate(Integer zoom) {
            if (zoom == null || zoom <= 0) {
                return this.generate();
            } else {
                return this.name + ("-" + zoom) + "." + (this.type == null ? "" : this.type);
            }
        }

        /**
         * author:gfl
         * email:gfl@cheok.com
         * 重载一个可以获取原图路径的接口
         *
         * @param zoom       缩放比例
         * @param isOriginal 是否原图
         * @return
         */
        public String generate(Integer zoom, Integer isOriginal) {
            if (isOriginal != null && isOriginal == 1) {
                return this.name + "-YT." + (this.type == null ? "" : this.type);
            }
            return this.generate(zoom);
        }

        public String generate() {
            return this.name + "." + (this.type == null ? "" : this.type);
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }
    }

}
